package com.viking.framework.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @see special handle factory aware
 * @author Administrator
 * 
 */
public class ObjectCreateProcessor implements BeanPostProcessor {

	public Object postProcessAfterInitialization(Object bean, String beanName)
			throws BeansException {
		Object result = null;
		BeanCreateFactoryAware _beanFacroy = null;
		if (bean instanceof BeanCreateFactoryAware) {
			_beanFacroy = (BeanCreateFactoryAware) bean;
		} else {
			return bean;
		}
		try {
			String _targetName = _beanFacroy.getTargetBeanName();
			result = _beanFacroy.getBeanFactory().getBean(_targetName);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public Object postProcessBeforeInitialization(Object bean, String beanName)
			throws BeansException {
		return bean;
	}

}
